// Pines
const int stepPin = 23;
const int dirPin  = 25;
const int enPin   = 5;  // Nuevo pin ENABLE

void setup() {
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(enPin, OUTPUT);

  digitalWrite(enPin, LOW); // Activar driver al inicio
}

void loop() {

  // --- Motor activo ---
  digitalWrite(enPin, LOW); // Asegura que esté encendido

  // Girar en un sentido
  digitalWrite(dirPin, HIGH);
  for(int i = 0; i < 200; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(800);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(800);
  }

  delay(1000);

  // Girar en sentido contrario
  digitalWrite(dirPin, LOW);
  for(int i = 0; i < 200; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(800);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(800);
  }

  delay(1000);

  // --- Desactivar driver ---
  digitalWrite(enPin, HIGH); // Motor se libera

  delay(3000); // Espera antes de repetir
}